<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>陈不知代码</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        
        li {
            list-style: none;
        }
        
        a {
            display: block;
            float: left;
            width: 100px;
            height: 50px;
            line-height: 50px;
            text-align: center;
            text-decoration: none;
            color: black;
            margin: 0 10px;
        }
        
        .xianshi {
            background-color: red;
            color: white;
        }
        
        .tab {
            width: 700px;
            height: 60px;
        }
        
        .chaoda {
            width: 700px;
            height: 560px;
            margin: 0 auto;
            margin-top: 100px;
        }
        
        .yi {
            width: 700px;
            height: 500px;
            background-color: darkgreen;
            /* display: none; */
        }
        
        .er {
            width: 700px;
            height: 500px;
            background-color: darkorange;
            display: none;
        }
        
        .san {
            width: 700px;
            height: 500px;
            background-color: deepskyblue;
            display: none;
        }
        
        .si {
            width: 700px;
            height: 500px;
            background-color: fuchsia;
            display: none;
        }
        
        .houmian {
            width: 700px;
            height: 500px;
            background-color: hotpink;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div class="chaoda">
        <div class="tab">
            <ul>
                <li>
                    <a href="javascript:;" class="xianshi">球鞋</a>
                </li>
                <li>
                    <a href="javascript:;">连衣裙</a>
                </li>
                <li>
                    <a href="javascript:;">笔记本电脑</a>
                </li>
                <li>
                    <a href="javascript:;">智能手机</a>
                </li>
            </ul>
        </div>
        <div class="dahe">
            <div class="yi item">球鞋</div>
            <div class="er item">连衣裙</div>
            <div class="san item">笔记本电脑</div>
            <div class="si item">智能手机</div>
        </div>
    </div>
    <div class="houmian">后面的内容，测试是否隐藏会影响后面的元素，测试后发现不影响</div>
    <script>
        var a = document.querySelectorAll('a');
        var div = document.querySelectorAll('.item');
        console.log(div);
        /* console.log(a); */
        /*  设置点击a链接变红 */
        for (var i = 0; i < a.length; i++) {
            a[i].setAttribute('index', i);
            a[i].addEventListener('click', function() {
                /* console.log('点击了'); */
                /* 杀死所有样式 */
                for (var j = 0; j < a.length; j++) {
                    a[j].className = '';
                }
                this.className = 'xianshi';
                var index = this.getAttribute('index');
                /* console.log(index); */
                for (var k = 0; k < div.length; k++) {
                    div[k].style.display = 'none';
                }
                div[index].style.display = 'block';

            })
        }
    </script>
</body>

</html>